<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../react18/react.development.js"></script>
    <script src="../react18/react-dom.development.js"></script>
    <script src="../react18/babel.min.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        class Child1 extends React.Component{
            render(){
                const {car,changeCar}=this.props;
                return <div>
                    <h3>我是拓海，我开的是{car}</h3>
                    <button onClick ={changeCar}>换车</button>
                    </div>
            }
        }
        class Child2 extends React.Component{
            render(){
                const {car,changeCar}=this.props;
                return <div>
                    <h3>我是藤原，我开的是{car}</h3>
                    <button onClick ={changeCar}>换车</button>
                    </div>
            }
        }
        class App extends React.Component{
            state = {
                car:"宾士",
            }
            render(){
                const {car}=this.state;
                return <div>
                    <h2>我是父亲,我开的是{car}</h2>
                    <hr />
                    <Child1 car={car} changeCar={this.changeCar} />
                    <hr />
                    <Child2 car={car} changeCar={this.changeCar} />
                    </div>
            }
            changeCar=()=>{
                this.setState({
                    car:"AE86"
                })
            }
        }
        ReactDOM.createRoot(document.getElementById("app")).render(<App />);
    </script>
</body>
</html>